from django.db import models

# Create your models here.
from Administrative_office_system.utils.BaseModel import BaseModel, TimeStampFileName, ChatStampFileName


class UserCommunicate(BaseModel):
    # 发件人	收件人	消息内容	是否已读	发件时间	是否删除	是否草稿	标题？	收件人删除？	文件
    # user_id = models.IntegerField(verbose_name='用户表id')
    sender = models.CharField(max_length=32, verbose_name='发件人')
    sender_job_num = models.CharField(max_length=32, verbose_name='发件人工号', default='')
    recipient = models.TextField(verbose_name='收信人')
    recipient_job_num = models.TextField(verbose_name='收信人工号列表', default='')
    message_content = models.TextField(verbose_name='消息内容')
    title = models.CharField(max_length=32,default='', verbose_name='标题')
    read = models.BooleanField(default=False, verbose_name='收信人是否已读')
    is_draft = models.BooleanField(default=False, verbose_name='是否草稿')
    send_is_deleted = models.BooleanField(default=False, verbose_name='发件人是否删除')
    receive_is_deleted = models.BooleanField(default=False, verbose_name='发件人是否删除')
    file_path = models.TextField(default='', verbose_name="附件列表")


    class Meta:
        # db_table = 'tb_user_communicate'
        verbose_name = '用户消息表'
        verbose_name_plural = verbose_name
        managed = True
        # ordering = ['-update_time']


class UserMessageInfo(BaseModel):
    # 发件人	收件人	消息内容	是否已读	发件时间	是否删除	是否草稿	标题？	收件人删除？	文件
    # user_id = models.IntegerField(verbose_name='用户表id')
    sender = models.CharField(max_length=32, verbose_name='发件人')
    sender_job_num = models.CharField(max_length=32, verbose_name='发件人工号', default='')
    recipient = models.TextField(verbose_name='收信人')
    recipient_job_num = models.TextField(verbose_name='收信人工号列表', default='')
    message_content = models.TextField(verbose_name='消息内容')
    title = models.CharField(max_length=225, default='', verbose_name='标题')
    read = models.BooleanField(default=False, verbose_name='收信人是否已读')
    is_draft = models.BooleanField(default=False, verbose_name='是否草稿')
    send_is_deleted = models.BooleanField(default=False, verbose_name='发件人是否删除')
    receive_is_deleted = models.TextField(default='', verbose_name='收件人删除列表')
    file_path = models.FileField(default='', upload_to=ChatStampFileName(r'ChatFile/'), )
    file_path_text = models.TextField(verbose_name='附件', blank=True)
    has_fished = models.TextField(verbose_name='已接收', blank=True)

    class Meta:
        verbose_name = '用户消息表'
        verbose_name_plural = verbose_name


class delete_letter(BaseModel):
    del_people = models.CharField(max_length=32, verbose_name='删除人')
    letter_id = models.CharField(max_length=32, verbose_name='删除信件ID')
    completely_cancel = models.BooleanField(default=False, verbose_name='是否永久删除')



# 邮箱主表
class InboxInfo(BaseModel):
    TYPE = (
        ('a', '未删除'),
        ('b', '已删除'),
        ('c', '彻底删除')
    )
    content = models.TextField(verbose_name='邮件内容')
    plain_text = models.TextField(verbose_name='邮件纯文本')
    title = models.CharField(max_length=500, default='', verbose_name='邮件标题')
    is_draft = models.BooleanField(default=False, verbose_name='是否草稿')
    deleted = models.CharField('是否删除', max_length=10, choices=TYPE, default='a')
    accessory_uuid = models.CharField(max_length=100, default='', verbose_name='附件唯一标识')
    proposer = models.ForeignKey(
        'personal_center.User',
        verbose_name="发件人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)

    class Meta:
        verbose_name = '站内信主表'
        verbose_name_plural = verbose_name

class InboxInfoPeople(BaseModel):
    STATUS = (
        ('unread', '未读'),
        ('read', '已读')
    )
    TYPE = (
        ('a', '未删除'),
        ('b', '已删除'),
        ('c', '彻底删除')
    )
    readed = models.CharField('是否已读', max_length=10, choices=STATUS, default='unread')
    deleted = models.CharField('收件人是否删除', max_length=10, choices=TYPE, default='a')
    recipient_name = models.CharField('接收人名称', max_length=50, default='')
    inbox_id = models.ForeignKey(
        'InboxInfo',
        verbose_name="邮件",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    recipient = models.ForeignKey(
        'personal_center.User',
        verbose_name="接收人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)

class chatting_records(BaseModel):
    from_user = models.ForeignKey('personal_center.User', verbose_name="发送消息人员", related_name="fromname", blank=False, null=False, on_delete=models.CASCADE)
    to_user = models.ForeignKey('personal_center.User', verbose_name='接收消息人员', related_name="toname", blank=False, null=False, on_delete=models.CASCADE)
    content = models.TextField(verbose_name='消息内容的json_encode', default='')
    status = models.CharField(max_length=11, default='0', verbose_name='消息的状态：0未读消息；1：已读消息，2消息已撤销')

class ChatGroups(BaseModel):
    group_user = models.ManyToManyField('personal_center.User', verbose_name="群组人员", blank=True, related_name='chart_group_user')
    room_id = models.CharField(max_length=100, default='1', verbose_name='聊天的房间id')
    group_name = models.CharField(max_length=100, default='', verbose_name='群组名称')

class ChatGroupsMessage(BaseModel):
    chat_groups_id = models.ForeignKey(
        'ChatGroups',
        verbose_name="群组",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    content = models.TextField(verbose_name='消息内容的json_encode', default='')

    class Meta:
        managed = True
        verbose_name = '群组消息'
        verbose_name_plural = verbose_name